//
//  ViewController.m
//  JuneAMNum
//
//  Created by June on 16/12/19.
//  Copyright © 2016年 June. All rights reserved.
//

#import "ViewController.h"
#import "JuneAnimationView.h"

@interface ViewController ()
@property (nonatomic, strong) JuneAnimationView *animationNum;
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    _animationNum = [[JuneAnimationView alloc] initWithFrame:CGRectMake( 10, 100, self.view.frame.size.width - 20, 100)];
    _animationNum.backgroundColor = [UIColor blackColor];
    _animationNum.textColor = [self randomColor];
    _animationNum.font = [UIFont fontWithName:@"HelveticaNeue-Bold" size:42];
    
    _animationNum.minLength = 1;
    
    UIButton *startBtn = [UIButton buttonWithType:UIButtonTypeSystem];
    startBtn.frame = CGRectMake( 50, CGRectGetMaxY(_animationNum.frame) + 50, self.view.frame.size.width - 100, 30);
    [startBtn setTitle:@"Start Animation" forState:UIControlStateNormal];
    [startBtn addTarget:self action:@selector(startAnimaTion) forControlEvents:UIControlEventTouchUpInside];
    
    [self.view addSubview:_animationNum];
    [self.view addSubview:startBtn];
    
    _animationNum.value = [NSNumber numberWithInt:arc4random() % 200000];
    [_animationNum startAnimation];
}

- (void)startAnimaTion
{
    _animationNum.textColor = [self randomColor];
    
    _animationNum.value = [NSNumber numberWithInt:arc4random() % 200000];
    [_animationNum startAnimation];
}

-(UIColor *)randomColor
{
    CGFloat r = arc4random_uniform(256) / 255.0;
    CGFloat g = arc4random_uniform(256) / 255.0;
    CGFloat b = arc4random_uniform(256) / 255.0;
    
    return [UIColor colorWithRed:r green:g blue:b alpha:1.0];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
